  $(function(){
    var baseurl=location.protocol+'//'+location.host,//嘟嘟平台环境根路径   
    statusurl='http://open.yonyoutelecom.cn',//状态服务器根路径 
    platurl='https://123.103.9.209:5003',//运营平台沙箱环境根路径   
//  platurl='http://test.cloud.yonyoutelecom.cn',//运营平台内部测试环境根路径   
//  platurl='http://cloud.yonyoutelecom.cn',//运营平台正式环境根路径
    version='v1',//插件版本号
    basePaths={//基础路径，不同版本h5插件相同
      statusUrl:statusurl+'/callback/getMeetStatus.do',//查询会议状态
      meet_detail_url:baseurl+'/v4/bill/getTelBillDetailsBySessionId.do',//查询通话明细
      account_check_url:baseurl+'/v4/business/hasArrearage.do',//查询是否有欠款
      recharge_detail_url:baseurl+'/v4/bill/getRechargeHistory.do',// 查询充值明细
      account_limit_url:baseurl+'/v4/business/queryOauthRelationUser.do',//个人账户额度
      account_resourcesinfo_url:baseurl+'/v4/business/queryResourcesAndAccountInfo.do',//查询个人账户及资源信息
      history_detail_url:baseurl+'/v4/bill/getBillDetails.do',//查询个人历史通话明细
      alipay_charge_url:platurl+'/business/html/regist/alipay/mobile_index.html',//运营平台支付宝充值页面
      cardpay_charge_url:platurl+'/business/html/regist/cardpay/mobile_cardpay_index.html',//运营平台充值卡充值页面
      getcode_url:baseurl+'/v4/business/getAskCode.do',//运营平台获取请求码路径
      status_url:statusurl+'/callback/startConference.do',//注册组织账户时，设置话单状态推送地址，保证状态可以推送到查询服务器
      sendVoiceNotice_url:baseurl+'/VOICE/sendVoiceNotice.do',//发送语音通知
      sendVoiceNoticeLet_url:baseurl+'/VOICE/sendVoiceNoticeLet.do',//发送语音通知
      sms_detail_url:baseurl+'/v4/bill/getSmsBillDetailsBySessionId.do',//语音通知通话明细
      union_account_url:baseurl+'/ua/unified_account.html',//统一账户地址
      dial_url:baseurl+'/DIAL/dial.do',//两方通话地址
      dialStop_url:baseurl+'/DIAL/dialStop.do',//两方通话挂断地址
      dial_detail_url:baseurl+'/v4/bill/getDialBillDetailsByPhoneNum.do',//两方通话明细
      abilityUrl:baseurl//能力地址
    },
    h5Paths={//h5插件服务路径
      raa_url:baseurl+'/v4/h5/registerAndAuthenticate.do',
      bs_url:baseurl+'/v4/h5/bootstrap.do',
      check_url:baseurl+'/v4/h5/checkAuthenticateAndAccount.do'
    },
    headerConfig={//是否显示页面标题
      showartitle:'1',//显示账户页面标题栏
      showhdtitle:'1',//显示通话历史页面标题栏
      showrdtitle:'1'//显示充值历史页面标题栏
    },
    params={
      isLoadContacts:'1'//默认获取通讯录数据
    },
    pagePaths={//index和页面路径映射关系
      0:{name:'starting.html'},//欢迎页
      1:{name:'index.html'},//通讯录页
      2:{
        name:'Launch_meeting.html',//发起通话页
        nextQueryString:function(){
          var caller=getCallerObject();
          var callee=getAllCalleesObject();
          if(callee!=null)
            Array.prototype.push.apply(caller.data,callee.slice(0,9));
          return '?data='+JSON.stringify(caller);
        }     
      },
      3:{name:'history_detail.html'},//通话记录页
      4:{name:'recharge_details.html'},//充值记录页      
      5:{name:'account_recharge.html'},//账户页面
      6:{name:'owning_pay.html'},//账户余额不足提示页面-非管理员
      7:{name:'owning_fee.html'},//账户余额不足提示页面-管理员
      8:{
          name:'register.html',//注册页
          nextQueryString:function(){ 
            return window.location.search;
          }
      },
      9:{name:'text_recording.html'},//文字留言发送页面
      10:{name:'call_meeting.html'},//有通话记录首页
      11:{name:'two_call.html'},//两方通话页面
      12:{name:'text_recording.html'}//文字留言页面
    };
    
    /**
     * 本地缓存，缓存会话变量和永久变量
     */
    var localCache={
        postfix:'_'+version,
        prefix:'dudu_',
        setSessionItems:function(){
          for (var i = 0; i < arguments.length; i++) {
            for ( var key in arguments[i]) {
              sessionStorage.setItem(localCache.prefix+key, arguments[i][key]);
            }
          }
        },
        setSessionItem:function(key,value){
          sessionStorage.setItem(localCache.prefix+key, value);
        },
        getSessionItem:function(key){
          return sessionStorage.getItem(localCache.prefix+key);
        },
        removeSessionItem:function(key){
        	sessionStorage.removeItem(localCache.prefix+key);
        },
        cacheItemIdentify:function(key,value){
          localStorage.setItem(key+localCache.postfix, value);
        },
        getItemIdentify:function(key){
          return localStorage.getItem(key+localCache.postfix);
        },
        load:function(loadedHeader){//缓存路径到session中
          if(loadedHeader)
            localCache.setSessionItems(basePaths,h5Paths,params,headerConfig);
          else
        	localCache.setSessionItems(basePaths,h5Paths,params);  
        },
        clear:function(){
        	for (var i = 0; i < sessionStorage.length; i++) {
				var key=sessionStorage.key(i);
				if(key.indexOf(localCache.prefix)>-1){
					sessionStorage.removeItem(key);
				}
			}
        }
    };
    
    window.localCache=localCache;
    /**
     * index-页面坐标
     * queryString-查询字符串
     * isBack-是否为返回
     */
    window.router=function(index,queryString,isBack){
      var path=pagePaths[index]||pagePaths[0],url=path.name;
      if(queryString){
         location.assign(url+queryString);
         return;
      }
      if(!isBack)
    	  isBack=false;
      var func=null,qs='';
      if(isBack&&path.previousQueryString){
    	  qs=path.previousQueryString();
      }else if(path.nextQueryString){
    	  qs=path.nextQueryString();
      }
      location.assign(url+qs);
    };
    
    /**
     * 给定src发起请求
     */
    window.createUrl=function(src){
      var iFrame;
      iFrame = document.createElement("iframe");  
      iFrame.setAttribute("src", src);  
      iFrame.setAttribute("style", "display:none;");  
      iFrame.setAttribute("height", "0px");  
      iFrame.setAttribute("width", "0px");  
      iFrame.setAttribute("frameborder", "0");  
      document.body.appendChild(iFrame);  
      iFrame.parentNode.removeChild(iFrame);  
      iFrame = null;
    }
    
    window.loadScript=function(src,callback){
    	var script = document.createElement("script");
	    script.type = "text/javascript";
	    if(callback&&typeof(callback)==='function'){
		    if(script.readyState){//IE
		        script.onreadystatechange = function(){
		            if (script.readyState == "loaded" || script.readyState == "complete"){
		                script.onreadystatechange = null;
		                callback();
		            }
		        };
		    }else {//Others
		        script.onload = function(){
		            callback();
		        };
		    }
	    }
	    script.src = url;
	    document.getElementsByTagName("head")[0].appendChild(script);
    }
    
    window.createClose=function(){
      var close=$('#close');
      if(!isMobileClient())//非移动端页面不显示退出
        close.css('display','none');
      else{
    	var supportUap=localCache.getSessionItem('supportUap');
    	if(supportUap==='1'){//支持uap移动端返回
    		loadScript(baseurl+'/h5/js/iuapmobile.frameworks.core-2.7.0.js');
    		close.on('click',function(){
        		var viewid = $cache.read("pagefromdudu");
        		if(viewid == null || viewid == ""){
        		  viewid  = "com.nengyuan.iapproval63.ApprovalInfo";
        		}
        		$view.open({
                  "viewid" : viewid,
                  "isKeep" : "false"
        		});
    		});
    	}else{
            close.on('click',function(){
                createUrl('close://dudu?app_key='+localCache.getSessionItem('account_identifer'));
            });
    	}
      }
    }
  });
   
  
    